package logic;

import guiDisplay.MovieComment;
import guiDisplay.MovieData;

import java.util.GregorianCalendar;
import java.util.TreeSet;

import data.MovieTuple;
import data.RatingTuple;
import data.SystemData;
import data.UserTuple;

public class SystemHandler {

	public SystemHandler(){
	}

//	public RatingTuple getRandomRec(){
//		return SystemData.getInstance().getRandomRec();
//	}

	public void addRating(String user , String movie, String rating , String description){
	//	MovieTuple movieTuple = SystemData.getInstance().getMovie(movie);
	//	movieTuple.increaseMovieRating(Integer.parseInt(rating));
	//	movieTuple.set_raters(movieTuple.get_raters()+1);
		UserTuple userTuple = SystemData.getInstance().getUser(user);
	//	RatingTuple ratingTuple = RatingTuple.createNew(movieTuple, userTuple, GregorianCalendar.getInstance().getTime().toString(), rating, description);
		SystemData.getInstance().addRating(user , movie, rating , description);
		ToGuiFacade.getInstance().showUserScreenAfterRating(user,userTuple.isAdmin());
	}

	public void changeRating(String user , String movie, String rate , String description){
		UserTuple userTuple = SystemData.getInstance().getUser(user);
		SystemData.getInstance().editRating(user,movie,description,rate,GregorianCalendar.getInstance().getTime().toString());
		ToGuiFacade.getInstance().showUserScreenAfterRating(user,userTuple.isAdmin());
	}

	public MovieData getMovieData(String name) {
		MovieTuple movie = SystemData.getInstance().getMovie(name);
		TreeSet<RatingTuple> ratings = movie.getRatings();
		MovieComment[] comments = new MovieComment[ratings.size()];
		int i = 0;
		System.out.println("rating size "+ratings.size());
		for (RatingTuple r : ratings){
			comments[i] = new MovieComment(r.get_user().get_name(),r.get_rating()+"",r.get_date(),r.get_description());
			i++;
		}
		MovieData d = new MovieData(movie.get_name(),movie.get_year()+"",""+movie.get_length(),movie.get_language(),movie.get_director(),movie.get_category(),movie.get_rating()+"",movie.get_raters()+"",movie.get_picture()+"",comments );
		return d;
	}

	public String[] getMovies() {
		return SystemData.getInstance().getMovieNames();
	}

	public Object[] getUsers(String user) {
		return SystemData.getInstance().getUserNames(user);
	}

}
